Import libraries and define settings
In [12]:
from openearthtools.io.delft3d.dep import Dep as depcls
from openearthtools.io.delft3d.grid import Grid as gridcls
import numpy as np
#import delft3doperators as d3do
gridfile = '../applications/delft3doperators/data/wl2a.grd'
sourcedepfile = '../applications/delft3doperators/data/refplanewl2a.dep'
targetdepfile = '../applications/delft3doperators/data/test2.dep'
pylab.rcParams['figure.figsize'] = 20, 8
Read grid and depth files and subsequently write new depth
In [13]:
grid = gridcls.fromfile(gridfile) #Read grid-file
dep = depcls.read(sourcedepfile,grid.shape) #Read dep-file
dep2 = dep.copy() #Read dep-file again
dep2.val = dep2.val + 1.0 #Adjust depth
dep2.write(targetdepfile) #Save depth
# Warning: (This is not how to do it)
#
# dep2 = dep
# dep2.val = dep.val + 1.0
#
# As it changes the value of dep.val
Plot curvilinear grid
In [14]:
fig, ax = plt.subplots(1,1)
ax.plot(grid.x.transpose(), grid.y.transpose(), 'g')
ax.plot(grid.x, grid.y, 'g')
ax.set_aspect('equal')
Plot depth before and after as 2d plot
In [15]:
print grid.x[1:3,1:3]
WARNING: grid and dep locations should be further checked
In [17]:
fig, ax = plt.subplots(2,1)
ax[0].pcolor(grid.x, grid.y, dep.val[0:-1,0:-1], vmin=6, vmax=10)
ax[0].set_aspect('equal')
ax[1].pcolor(grid.x, grid.y, dep2.val[0:-1,0:-1],vmin=6, vmax=10)
ax[1].set_aspect('equal')
Plot depth before and after as 1d plot
In [ ]:
fig, ax = plt.subplots(1,1)
ax.plot(range(0,dep2.val.shape[0]),dep2.val[:,23], 'g')
ax.plot(range(0,dep.val.shape[0]),dep.val[:,23], 'r')
In [ ]: